// haha vscode is great
// I love it
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define CMD_NAME_LEN 128
#define CMD_DESC_LEN 1024
#define CMD_MAX_NUM 10

typedef struct DataNode
{
    char* cmd;
    char* desc;
    void (*handler)();
    struct DataNode *next;
} tDataNode;

void help();
void quit();

static tDataNode list[] = 
{
    {"help","this is help cmd!",help,&list[1]},
    {"quit","quit from menu!",quit,&list[2]},
    {"version","menu program v1.0",NULL,NULL}
};

int main()
{
    char cmd[CMD_NAME_LEN];
    while(1)
    {
           printf("> ");
           scanf("%s",cmd);
           tDataNode *p = list;
           while(p != NULL)
           {
               if(strcmp(cmd,p->cmd) == 0)
               {
                   printf("%s\n",p->desc);
                   if(p->handler != NULL)
                   {
                       p->handler();
                   }
                   break;
               }
               p=p->next;
           }
           if(p == NULL)
           {
               printf("this is wrong cmd!\n");
           }
    }
    return 0;
}

void help()
{
    tDataNode *p = list;
    while(p != NULL)
    {
        printf("%s - %s\n",p->cmd,p->desc);
        p=p->next;
    }
}

void quit()
{
    printf("bye bye!\n");
    exit(0);
}

